package at.guigu.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@MapperScan("at.guigu.mapper")
public class MpConfig {

    /**
     * 添加拦截器方法
     * @return
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        // 定义MyBatisPlus的拦截器
        MybatisPlusInterceptor mpInterceptor = new MybatisPlusInterceptor();
        // 配置分页拦截器---注意：若有多个数据源则可以不配具体类型，否则都建议配上具体的DbType（即数据库）
        mpInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return mpInterceptor;
    }
}